/*
 * Balloon.java
 * 
 * version 1.0
 * 
 * 11/21/2011
 * 
 * AOI
 */
package com.jcj.jumper;

import com.jcj.gd2d.DynamicGameObject;

/**
 * @author AOI
 * 
 * @version 1.0
 * 
 * Declara los movimientos dentro del minijuego de los globos
 */
public class Balloon extends DynamicGameObject {
	public static final int BALLOON_STATE_SET = 0;
	public static final int BALLOON_STATE_MOVE = 1;
	public static final int BALLOON_STATE_POP = 2;
	public static final float BALLOON_MOVE_VELOCITY = 11;
	public static final float BALLOON_WIDTH = 0.8f;
	public static final float BALLOON_HEIGHT = 0.8f;
	
	 	int state;
	    float stateTime;
	    boolean answer;

	    public Balloon(float x, float y, boolean answer) {
	        super(x, y, BALLOON_WIDTH, BALLOON_HEIGHT);
	        state = BALLOON_STATE_SET;
	        stateTime = 0;
	        this.answer = answer;
	    }
	    
	    /**
	     * 
	     * @return  regresa si el globo es la respuesta correcta
   		 *
	     */
	    
	    public boolean getAnswer(){
	    	return answer;
	    }
	    /**
	     * 
	     * @param answer indica si el globo es la respuesta correcta
	     */
	    public void setValue(boolean answer){
	    	this.answer = answer;
	    }

	    public void update(float deltaTime) {
	        velocity.add(World.gravity.x * deltaTime, World.gravity.y * deltaTime);
	        position.add(velocity.x * deltaTime, velocity.y * deltaTime);
	        bounds.lowerLeft.set(position).sub(bounds.width / 2, bounds.height / 2);

	        if (velocity.y > 0 && state != BALLOON_STATE_SET) {
	            if (state != BALLOON_STATE_SET) {
	                state = BALLOON_STATE_SET;
	                stateTime = 0;
	            }
	        }

	        if (velocity.y < 0 && state != BALLOON_STATE_POP) {
	            if (state != BALLOON_STATE_POP) {
	                state = BALLOON_STATE_POP;
	                stateTime = 0;
	            }
	        }

	        if (position.x < 0)
	            position.x = World.WORLD_WIDTH;
	        if (position.x > World.WORLD_WIDTH)
	            position.x = 0;

	        stateTime += deltaTime;
	    }

	    public void hitLife() {
	        velocity.set(0, 0);
	        state = BALLOON_STATE_POP;
	        stateTime = 0;
	    }

	    public void hitAnswer() {
	        velocity.set(0,0);
	        state = BALLOON_STATE_POP;
	        stateTime = 0;
	    }

	    public void cut() {
	        velocity.y = BALLOON_MOVE_VELOCITY * 1.5f;
	        state = BALLOON_STATE_MOVE;
	        stateTime = 0;
	    }

}
